import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { Router } from '@angular/router';


interface FormInfo{
  name:string,
  email:string,
  phone:string
}

@Component({
  selector: 'app-contact-new',
  templateUrl: './contact-new.component.html',
  styleUrls: ['./contact-new.component.less']
})
export class ContactNewComponent implements OnInit {

  public formData:FormInfo = {
    name:'',
    email:'',
    phone:''
  };



  constructor(private http:HttpClient,private router:Router) { }

  ngOnInit() {
  }

  submitHandle(){
    this.http.post('http://localhost:3000/contacts',this.formData)
      .toPromise()
      .then(res=>{
        this.router.navigate(['/contacts'])
      })
      .catch(err=>{
        alert('提交失败');
      })
  }

}
